import axios from '../utils/request'

const instance = axios.create({
  baseURL: 'http://localhost:8080',
  timeout: 12000
})

export function get(url, param) {
  return new Promise((resolve, reject) => {
    instance.get(url, { params: param }).then(res => {
      resolve(res)
    }).catch(err => {
      reject(err)
    })
  })
}

export function post(url, params) {
  return new Promise((resolve, reject) => {
    instance.post(url, params).then(res => {
      resolve(res.data)
    }).catch(err => {
      reject(err)
    })
  })
}

export function put(url, params, headers) {
  return new Promise((resolve, reject) => {
    instance.put(url, { params, headers }).then(res => {
      resolve(res)
    }).catch(err => {
      reject(err)
    })
  })
}

export function del(url, params, headers) {
  return new Promise((resolve, reject) => {
    instance.delete(url, { params, headers }).then(res => {
      resolve(res)
    }).catch(err => {
      reject(err)
    })
  })
}

